package org.travel_system.mapper;

import org.apache.ibatis.annotations.*;
import org.travel_system.pojo.Restaurant;

import java.util.List;

@Mapper
public interface RestaurantMapper {
    //查询餐馆列表
    @Select("select * from restaurant")
    List<Restaurant> getRestaurants();

    //通过名字查询
    @Select("select * from restaurant where restaurant_name=#{name}")
    Restaurant getRestaurantByName(String name);

    //添加餐馆
    @Insert("insert into restaurant(restaurant_name, phone_number, photo, per_capita,cuisine,address,business_hours)" +
            "values (#{restaurantName},#{phoneNumber},#{photo},#{perCapita},#{cuisine},#{address},#{businessHours})")
    int addRestaurant(Restaurant restaurant);
    //删除餐馆
    @Delete("delete from restaurant where restaurant_name=#{name}")
    int deleteRestaurantByName(String name);

    //更新餐馆信息
    @Update("update restaurant set phone_number=#{phoneNumber},photo=#{photo},per_capita=#{perCapita},cuisine=#{cuisine},address=#{address},business_hours=#{businessHours} where restaurant_name=#{restaurantName}")
    int updateRestaurant(Restaurant restaurant);

    //模糊搜索餐馆
    @Select("SELECT * FROM restaurant WHERE restaurant_name LIKE CONCAT('%', #{name}, '%')")
    List<Restaurant> getSearchRestaurantByName(@Param("name") String name);
}
